package com.cug.smartranch.animal.admin.controller;

import com.cug.smartranch.animal.admin.dto.req.AnimalLocationSaveReqDTO;
import com.cug.smartranch.animal.admin.dto.resp.AnimalHealthQueryRespDTO;
import com.cug.smartranch.animal.admin.dto.resp.AnimalLocationQueryRespDTO;
import com.cug.smartranch.animal.admin.service.AnimalLocationService;
import com.cug.smartranch.framework.result.Result;
import com.cug.smartranch.framework.web.Results;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 动物控制层
 */
@RestController
@RequiredArgsConstructor
@Tag(name = "动物坐标管理")
@RequestMapping("/api/animal-admin/animal/location")
public class AnimalLocationController {

    private final AnimalLocationService animalLocationService;

    @Operation(summary = "用户创建当前时刻动物坐标记录")
    @PostMapping("/create")
    public Result<Void> createAnimalLocation(@RequestBody AnimalLocationSaveReqDTO requestParam) {
        animalLocationService.createAnimalLocation(requestParam);
        return Results.success();
    }

    @Operation(summary = "查询某个动物近期100条坐标记录")
    @GetMapping("/find")
    public Result<List<AnimalLocationQueryRespDTO>> findAnimalLocation(@RequestParam("animalId") Long animalId) {
        List<AnimalLocationQueryRespDTO> respDTO = animalLocationService.findAnimalHealth(animalId);
        return Results.success(respDTO);
    }

    @Operation(summary = "（后端测试使用）创建当前时刻之前100条动物坐标记录")
    @PostMapping("/createMock")
    public Result<Void> createMockAnimalLocation(@RequestParam("animalId") Long animalId) {
        animalLocationService.createMockAnimalLocation(animalId);
        return Results.success();
    }
}
